﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfApplication1.Class.Bean;
namespace WpfApplication1.Control
{
    /// <summary>
    /// Logique d'interaction pour ControlAdmin.xaml
    /// </summary>
    public partial class ControlAdmin : UserControl
    {
        ClassCurrentUserSingleton user;
        public ControlAdmin()
        {
            InitializeComponent();
            labelAssign.Visibility = Visibility.Hidden;
            listAssign.Visibility = Visibility.Hidden;
            butValid.Visibility = Visibility.Hidden;
            
            

            user = ClassCurrentUserSingleton.Instance;
            //lister toutes les personnes sur le projet
            List<SearchField> list = new List<SearchField>();
            list.Add(new SearchField("IdProjet", user.IdProjet, SearchField.EGAL_A));
            List<ClassPersonne> personnes = ClassPersonne.Search(list);
            //afficher dans control
            Binding source = new Binding();
            source.Source = personnes;
            this.listPers.SetBinding(DataContextProperty, source);
            this.listPers.DisplayMemberPath = "Nom";
              
        }

        private void selected(object sender, SelectionChangedEventArgs e)
        {
            nom.Text = ((ClassPersonne)this.listPers.SelectedItem).Nom;
            prenom.Text = ((ClassPersonne)this.listPers.SelectedItem).Prenom;
            role.Text = ((ClassPersonne)this.listPers.SelectedItem).Role;
            login.Text = ((ClassPersonne)this.listPers.SelectedItem).Login;
            password.Text = ((ClassPersonne)this.listPers.SelectedItem).Password;
            butAj.Content = "Modifier Utilisateur";
        }

        private void click(object sender, RoutedEventArgs e)
        {
            labelList.Visibility = Visibility.Hidden;
            listPers.Visibility = Visibility.Hidden;
            labelAssign.Visibility = Visibility.Visible;
            listAssign.Visibility = Visibility.Visible;
            butAj.Visibility = Visibility.Hidden;
            butSup.Visibility = Visibility.Hidden;
            butValid.Visibility = Visibility.Visible;

            ClassProjet proj = new ClassProjet();
            //lister toutes les projets
            List<SearchField> list = new List<SearchField>();
            //list.Add(new SearchField("IdProjet", user.IdProjet, SearchField.EGAL_A));
            List<ClassProjet> listproj = ClassProjet.Search(list);
            //afficher dans control
            Binding source = new Binding();
            source.Source = listproj;
            this.listAssign.SetBinding(DataContextProperty, source);
            this.listAssign.DisplayMemberPath = "NomProjet";
            
         }

        private void valid(object sender, RoutedEventArgs e)
        {
            ClassPersonne pers = new ClassPersonne();
            pers.Nom = nom.Text;
            pers.Prenom = prenom.Text;
            pers.Login = login.Text;
            pers.Password = password.Text;
            pers.Role = role.Text;
            pers.IdProjet = ((ClassProjet)this.listAssign.SelectedItem).Id;

            ClassPersonne.SaveOrUpdate(pers);

        }

        private void supprimer(object sender, RoutedEventArgs e)
        {
            ClassPersonne pers = ClassPersonne.Read(((ClassPersonne)this.listPers.SelectedItem).Id, new ClassPersonne());

        }
        
        //


        //


    }
}
